Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: exclude pruning from tendermint update client in ante handler execution #6278

Merged
merged 12 commits into from
May 20, 2024

Conversation

colin-axner
Copy link
Contributor

@colin-axner colin-axner commented May 8, 2024

Description

ref: #6232

can only be backported to v8.3.x as SDK does not have exec mode api in context on v0.47.x


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

Summary by CodeRabbit

  • Performance Enhancements
    • Improved performance by excluding pruning from Tendermint client updates during ante handler executions.

Copy link
Contributor

coderabbitai bot commented May 8, 2024

Walkthrough

Walkthrough

The recent update enhances the performance of the core/ante module by optimizing the Tendermint client updates. Specifically, it excludes pruning operations during ante handler executions, resulting in a more efficient processing flow.

Changes

File Path Change Summary
core/ante Added performance enhancement by excluding pruning from Tendermint client updates in ante handler executions.
CHANGELOG.md Documented the performance enhancement introduced in the core/ante module.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@colin-axner colin-axner marked this pull request as ready for review May 8, 2024 14:45
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Out of diff range and nitpick comments (1)
modules/core/keeper/msg_server.go (1)

491-494: Consider adding a comment explaining the rationale behind the early return condition.

This helps maintain clarity for future code maintenance and understanding the specific conditions under which application callbacks are skipped.

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between edd41da and 9b9adbe.
Files selected for processing (4)
  • modules/core/ante/ante_test.go (2 hunks)
  • modules/core/keeper/msg_server.go (1 hunks)
  • modules/light-clients/07-tendermint/update.go (1 hunks)
  • modules/light-clients/07-tendermint/update_test.go (1 hunks)
Additional Context Used
Path-based Instructions (4)
modules/light-clients/07-tendermint/update.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

modules/core/ante/ante_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

modules/light-clients/07-tendermint/update_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

modules/core/keeper/msg_server.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (3)
modules/light-clients/07-tendermint/update.go (1)

140-143: Skip pruning logic during CheckTx and ReCheckTx to enhance performance.

This change aligns with the PR's objective to optimize performance by avoiding unnecessary pruning during transaction checks. Ensure that this modification does not inadvertently affect other functionalities by thorough testing, especially in scenarios where state updates are critical.

modules/core/ante/ante_test.go (1)

346-359: Ensure new test case adequately covers scenarios where app callbacks are skipped.

This test case is crucial for verifying that the new logic to skip application callbacks under certain conditions works as intended. It's important to ensure that this test covers all relevant scenarios and edge cases to prevent regressions or unexpected behavior in production.

modules/light-clients/07-tendermint/update_test.go (1)

560-613: Ensure the new pruning logic is covered by tests.

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Excellent work getting this smashed out quickly with the tests 🚀

modules/core/ante/ante_test.go Outdated Show resolved Hide resolved
@damiannolan
Copy link
Member

looks like a lot of e2e test failures, are they related? 👀

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9b9adbe and b795527.
Files selected for processing (1)
  • modules/core/ante/ante_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/core/ante/ante_test.go

@colin-axner colin-axner marked this pull request as draft May 8, 2024 15:40
@colin-axner
Copy link
Contributor Author

Looks like hermes might be using events in checktx for write ack which is why e2e's fail to relay. By skipping app callbacks, we cannot emit those events

@colin-axner
Copy link
Contributor Author

Looks to be that tx simulation uses a context that has IsCheckTx as true. The if statement can be changed to use the exec mode instead

@damiannolan damiannolan marked this pull request as ready for review May 8, 2024 16:20
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between b795527 and 6c55bab.
Files selected for processing (1)
  • modules/core/keeper/msg_server.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/core/keeper/msg_server.go

@damiannolan
Copy link
Member

Tested transfer e2e locally with cosmos/cosmos-sdk#20342 and seems to pass when context execMode is assigned correctly for simulateTx.

--- PASS: TestTransferTestSuite (209.05s)
    --- PASS: TestTransferTestSuite/TestMsgTransfer_Succeeds_Nonincentivized (209.05s)
        --- PASS: TestTransferTestSuite/TestMsgTransfer_Succeeds_Nonincentivized/ensure_capability_module_BeginBlock_is_executed (15.11s)
        --- PASS: TestTransferTestSuite/TestMsgTransfer_Succeeds_Nonincentivized/native_IBC_token_transfer_from_chainA_to_chainB,_sender_is_source_of_tokens (14.09s)
        --- PASS: TestTransferTestSuite/TestMsgTransfer_Succeeds_Nonincentivized/tokens_are_escrowed (0.01s)
        --- PASS: TestTransferTestSuite/TestMsgTransfer_Succeeds_Nonincentivized/start_relayer (20.15s)
        --- PASS: TestTransferTestSuite/TestMsgTransfer_Succeeds_Nonincentivized/packets_are_relayed (0.01s)
        --- PASS: TestTransferTestSuite/TestMsgTransfer_Succeeds_Nonincentivized/metadata_for_IBC_denomination_exists_on_chainB (0.00s)
        --- PASS: TestTransferTestSuite/TestMsgTransfer_Succeeds_Nonincentivized/non-native_IBC_token_transfer_from_chainB_to_chainA,_receiver_is_source_of_tokens (14.07s)
        --- PASS: TestTransferTestSuite/TestMsgTransfer_Succeeds_Nonincentivized/tokens_are_escrowed#01 (0.01s)
        --- PASS: TestTransferTestSuite/TestMsgTransfer_Succeeds_Nonincentivized/packets_are_relayed#01 (0.01s)
        --- PASS: TestTransferTestSuite/TestMsgTransfer_Succeeds_Nonincentivized/tokens_are_un-escrowed (0.00s)
PASS
ok      github.com/cosmos/ibc-go/e2e/tests/transfer     210.557s

@@ -488,6 +488,11 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack
return nil, errorsmod.Wrap(err, "receive packet verification failed")
}

// performance: return early for the redundant relayer ante handler
if (ctx.IsCheckTx() || ctx.IsReCheckTx()) && ctx.ExecMode() != sdk.ExecModeSimulate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For backport to v7.5 we should just add a new func which plumbs through the simulate bool from ante. We can do similar to the checkTxUpdateClient method I added on the ante handler itself.

There is no ability to check runTxModeSimulate on the v0.47 line (before it was changed to "execMode")

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6c55bab and c37a8c7.
Files selected for processing (2)
  • modules/light-clients/07-tendermint/update.go (1 hunks)
  • modules/light-clients/07-tendermint/update_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • modules/light-clients/07-tendermint/update.go
  • modules/light-clients/07-tendermint/update_test.go

@colin-axner colin-axner changed the title perf: exclude app callback from recvpacket and pruning from tendermint update client perf: exclude pruning from tendermint update client in ante handler execution May 13, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between c37a8c7 and 62b5ca7.
Files selected for processing (2)
  • modules/light-clients/07-tendermint/update.go (1 hunks)
  • modules/light-clients/07-tendermint/update_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • modules/light-clients/07-tendermint/update.go
  • modules/light-clients/07-tendermint/update_test.go

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful, lgtm! 🙏🏻

Comment on lines +142 to +146
// performance: do not prune in checkTx
// simulation must prune for accurate gas estimation
if (!ctx.IsCheckTx() && !ctx.IsReCheckTx()) || ctx.ExecMode() == sdk.ExecModeSimulate {
cs.pruneOldestConsensusState(ctx, cdc, clientStore)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 62b5ca7 and b8ee7e3.
Files selected for processing (1)
  • modules/light-clients/07-tendermint/update_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/light-clients/07-tendermint/update_test.go

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @colin-axner. Do you think we should a changelog entry for this one?

@colin-axner
Copy link
Contributor Author

Do you think we should a changelog entry for this one?

We were thinking of adding a single changelog for all the improvements, but I guess since they will be split up in backports I can add one

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Out of diff range and nitpick comments (3)
CHANGELOG.md (3)

Line range hint 193-193: Remove trailing spaces to maintain clean and professional documentation.

- * (core/ante) [\#6278](https://github.com/cosmos/ibc-go/pull/6278) Performance: Exclude pruning from tendermint client updates in ante handler executions. 
+ * (core/ante) [\#6278](https://github.com/cosmos/ibc-go/pull/6278) Performance: Exclude pruning from tendermint client updates in ante handler executions.

Line range hint 243-243: Remove trailing spaces to maintain clean and professional documentation.

- * (core/ante) [\#6278](https://github.com/cosmos/ibc-go/pull/6278) Performance: Exclude pruning from tendermint client updates in ante handler executions. 
+ * (core/ante) [\#6278](https://github.com/cosmos/ibc-go/pull/6278) Performance: Exclude pruning from tendermint client updates in ante handler executions.

Line range hint 178-178: Replace the bare URL with a markdown link for better readability and consistency.

- * [\#6232](https://github.com/cosmos/ibc-go/issues/6232) Bump CometBFT to v0.38.7.
+ * ([\#6232](https://github.com/cosmos/ibc-go/issues/6232)) Bump CometBFT to v0.38.7.
Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between b8ee7e3 and 9062819.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional Context Used
Path-based Instructions (1)
CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Additional comments not posted (1)
CHANGELOG.md (1)

68-68: Ensure the changelog entry for PR #6278 is linked to the correct PR and issue.

Verification successful

The PR link for #6278 in the changelog entry is correct.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the PR and issue links for the changelog entry.

# Test: Search for the PR and issue links in the changelog. Expect: Correct links.
rg --type md '\[\#6278\]\(https://github.com/cosmos/ibc-go/pull/6278\)' CHANGELOG.md
rg --type md '\[\#6232\]\(https://github.com/cosmos/ibc-go/issues/6232\)' CHANGELOG.md

Length of output: 175



Script:

#!/bin/bash
# Description: Verify the PR link for the changelog entry.

# Test: Search for the PR link in the changelog. Expect: Correct link.
rg --type md '\[\#6278\]\(https://github.com/cosmos/ibc-go/pull/6278\)' CHANGELOG.md

Length of output: 86



Script:

#!/bin/bash
# Description: Verify the PR link for the changelog entry with a broader search pattern.

# Test: Search for the PR link in the changelog. Expect: Correct link.
rg --type md '#6278' CHANGELOG.md

Length of output: 190

Copy link

sonarcloud bot commented May 20, 2024

Quality Gate Passed Quality Gate passed for 'ibc-go'

Issues
9 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@colin-axner colin-axner merged commit 67b23cd into main May 20, 2024
78 checks passed
@colin-axner colin-axner deleted the colin/6232-antehandler-perf-exclusions branch May 20, 2024 13:23
mergify bot pushed a commit that referenced this pull request May 20, 2024
…xecution (#6278)

* performance: exit early on recvpacket to exclude app callbacks

* perf: skip pruning on check tx and recheck tx

* change fmt.Errorf to errors.New

* fix: check execMode simulate in conditional

* revert: recv packet changes

* fix: account for simulation in pruning check

* fix: reuse checkTx ctx

* chore: add changelog

---------

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
(cherry picked from commit 67b23cd)

# Conflicts:
#	modules/light-clients/07-tendermint/update_test.go
colin-axner added a commit that referenced this pull request May 20, 2024
…xecution (backport #6278) (#6331)

* perf: exclude pruning from tendermint update client in ante handler execution (#6278)

* performance: exit early on recvpacket to exclude app callbacks

* perf: skip pruning on check tx and recheck tx

* change fmt.Errorf to errors.New

* fix: check execMode simulate in conditional

* revert: recv packet changes

* fix: account for simulation in pruning check

* fix: reuse checkTx ctx

* chore: add changelog

---------

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
(cherry picked from commit 67b23cd)

# Conflicts:
#	modules/light-clients/07-tendermint/update_test.go

* fix: merge conflicts

---------

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-v8.3.x priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants